import {request} from "@/network/request";

// 获取全部博客文章
export function getArticles(){
  return request({
    url: '/blog/articles/'
  })
}

// 新增一篇文章
export function postArticles(title, abstract, content){
  return request({
    method: "post",
    url: '/blog/articles/',
    data: {
      article_title: title,
      article_abstract: abstract,
      article_content: content
    }
  })
}

// 根据id获取单篇文章
export function getArticle(id){
  return request({
    url: '/blog/articles/'+id+'/'
  })
}

export function putArticle(id, title, abstract, content){
  return request({
    method: "put",
    url: '/blog/articles/'+id+'/',
    data: {
      article_title: title,
      article_abstract: abstract,
      article_content: content
    }
  })
}

export function deleteArticle(id){
  return request({
    method: "delete",
    url: '/blog/articles/'+id+'/'
  })
}

export function articleChangeTags(articleId, tagIds){
  return request({
    method: "post",
    url: '/blog/articles/'+articleId+'/article_op_tag/',
    data: {
      tag_ids: tagIds
    }
  })
}

// 获取全部分类标签
export function getSortTags(){
  return request({
    url: '/blog/article_tags/'
  })
}

export function postSortTags(tagName){
  return request({
    method: "post",
    url: '/blog/article_tags/',
    data: {
      tag_name: tagName
    }
  })
}

// 根据id获取单个分类标签以及该标签下有那些文章
export function getSortTag(id) {
  return request({
    url: '/blog/article_tags/'+id+'/'
  })
}

export function putSortTag(id, tagName){
  return request({
    method: "put",
    url: '/blog/article_tags/'+id+'/',
    data: {
      tag_name: tagName
    }
  })
}

export function deleteSortTag(id){
  return request({
    method: "delete",
    url: '/blog/article_tags/'+id+'/'
  })
}


export function postFiles(formData){
  return request({
    method: "post",
    url: '/file/upload/',
    headers:{
      'Content-Type':'multipart/form-data'
    },
    data: formData
  })
}
